<form id="myform" name="myform"   class="form" action="<?php echo site_url("welcome/register_edit/".$cust['register_id']); ?>" method="post"  >
<div id="form_left">
<div id="form_h1"></div>
<div style="clear: both;"></div>
  <?php //echo  validation_errors('<div class="error"> <span class="strong"></span>', '<span title="Dismiss" class="close"></span></div>'); ?>
<?php //print_r($_POST); ?>
<input type="hidden" name="full_address" value="<?php echo set_value("full_adress",$cust["full_address"]); ?>" />
<input type="hidden" name="sex" value="<?php echo set_value("sex",$cust["sex"]); ?>" />
<!-- ข้อมุลตามบัตรประชาชน -->
 <div class="field" >
 <div>คำนำหน้า:<?php echo form_error('prefix_name', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="prefix_name">
<option value="0">เลือก</option>
<option value="นาย" >นาย</option>
<option value="นางสาว">นางสาว</option>
<option value="นาง">นาง</option>
</select>
</div>
 <div class="field" >
<div>ชื่อจริง:<?php echo form_error('firstname', '<span class="field-error">', '</span>'); ?></div><br/>
<input type="text" name="firstname"  value="<?php echo set_value("firstname",$cust["firstname"]); ?>"/>
</div>
<div class="field">
<div>นามสกุล:<?php echo form_error('lastname', '<span class="field-error">', '</span>'); ?></div><br/>
 <input type="text" name="lastname" value="<?php echo set_value("lastname",$cust["lastname"]) ?>" />
</div>

 <div class="field" >
<div>เลขที่บัตรประจำตัวประชาชน:<?php echo form_error('card_code', '<span class="field-error">', '</span>'); ?></div><br/>
<input style="width: 160px;" type="text" name="card_code" value="<?php echo set_value("card_code",$cust["card_code"]); ?>" />

</div>

<div style="clear: both;"></div>
<div class="field" style="width:235px;"><div>วัน<?php echo form_error('birth_day', '<span class="field-error">', '</span>'); ?>/เดือน<?php echo form_error('birth_month', '<span class="field-error">', '</span>'); ?>/ปีเกิด:<?php echo form_error('birth_year', '<span class="field-error">', '</span>'); ?></div><br/>


<select style="width:60px;" name="birth_day">
                      <option value="0">วันที่</option>
                      				<?php for($i=1;$i<=31;$i++){ ?>
					                    <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
					                    <?php } ?>
                                        </select>
                                        <select style="width:100px;"   name="birth_month">
                        <option value="0"  >เดือน</option>
			                        <option value="1">มกราคม</option>
                                                <option value="2">กุมภาพันธ์</option>
                                                <option value="3">มีนาคม</option>
                                                <option value="4">เมษายน</option>
                                                <option value="5">พฤษภาคม</option>
                                                <option value="6">มิถุนายน</option>
                                                <option value="7">กรกฎาคม</option>
                                                <option value="8">สิงหาคม</option>
                                                <option value="9">กันยายน</option>
                                                <option value="10">ตุลาคม</option>
                                                <option value="11">พฤศจิกายน</option>
                                                <option value="12">ธันวาคม</option>
                                              </select>
<select style="width:65px;" name="birth_year">
<option value="0">ปี</option>
<?php for($i=2545;$i>=2485; $i--){ ?>
  <option value="<?php echo $i; ?>" ><?php echo $i; ?></option>
   <?php } ?>
</select>
</div>
 <div class="field" >
<div>บ้านเลขที่:<?php echo form_error('home_street', '<span class="field-error">', '</span>'); ?></div><br/>
<input type="text" style="width: 58px;" name="home_street"  value="<?php echo set_value("home_street",$cust["home_street"]); ?>"/>
</div>
 <div class="field" >
<div>หมูบ้าน:<span>(Optional)</span></div><br/>
<input type="text" name="moo"  value="<?php echo set_value("moo",$cust["moo"]); ?>"/>
</div>
 <div class="field" >
<div>ถนน:<span>(Optional)</span></div><br/>
<input type="text" name="road"  value="<?php echo set_value("road",$cust["road"]); ?>"/>
</div>

<div style="clear: both;"></div>
 <div class="field" >
<div>ซอย:<span>(Optional)</span></div><br/>
<input type="text" name="soi"  value="<?php echo set_value("soi",$cust["soi"]); ?>"/>
</div>
 <div class="field" >
<div>จังหวัด:<?php echo form_error('province_id', '<span class="field-error">', '</span>'); ?></div><br/>
<?php $provinces =  $this->db->get("province")->result_array(); ?>
<select name="province_id" onchange="province_change('district_id',this);" >
<option value="0">โปรดเลือก</option>
	<?php foreach($provinces as $row){?>
	<option value="<?php echo $row["province_id"]; ?>"><?php echo $row["province_name"]; ?></option>
	<?php } ?>
</select>
</div>
 <div class="field" >
<div>เขต/อำเภอ:<?php echo form_error('district_id', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="district_id" onchange="district_change('sub_district_id',this);">
<option>เลือก</option>
</select>
</div>
 <div class="field" >
<div>ตำบล/แขวง:<?php echo form_error('sub_district_id', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="sub_district_id" >
<option>เลือก</option>

</select>
</div>

 <div class="field" >
<div>รหัสไปรษณีย์:<?php echo form_error('zipcode', '<span class="field-error">', '</span>'); ?></div><br/>
<input type="text" name="zipcode"  value="<?php echo set_value("zipcode",$cust["zipcode"]); ?>"/>
</div>

<div style="clear: both;"></div>

<div id="form_h2"></div>
<div style="clear: both;"></div>


<!-- end ข้อมุลตามบัตรประชาชน -->


<!-- ทีสำหรับติดต่อ -->
<div style="margin-bottom: 13px; margin-top: -10px; ">
<input  name="same_address[]" <?php echo set_checkbox('same_address[]', '1'); ?>  value="1" type="checkbox" onclick="copy_to_contact();" />ที่อยู่เดียวกับที่อยู่ตามบัตรประจำตัวประชาชน
</div>
<div class="field">
<div>บ้านเลขที่:<?php echo form_error('home_street2', '<span class="field-error">', '</span>'); ?></div><br/>
<input  style="width: 58px;" type="text" name="home_street2"  value="<?php echo set_value("home_street2",$cust["home_street2"]); ?>"/>
</div>
 <div class="field" >
<div>หมูบ้าน:<span>(Optional)</span></div><br/>
<input type="text" name="moo2"  value="<?php echo set_value("moo2",$cust["moo2"]); ?>"/>
</div>
 <div class="field" >
<div>ถนน:<span>(Optional)</span></div><br/>
<input type="text" name="road2"  value="<?php echo set_value("road2",$cust["road2"]); ?>"/>
</div>


 <div class="field" >
<div>ซอย:<span>(Optional)</span></div><br/>
<input type="text" name="soi2"  value="<?php echo set_value("soi2",$cust["soi2"]); ?>"/>
</div>
<div style="clear: both;"></div>
 <div class="field" >
<div>จังหวัด:<?php echo form_error('province_id2', '<span class="field-error">', '</span>'); ?></div><br/>
<?php $provinces =  $this->db->get("province")->result_array(); ?>
<select name="province_id2" onchange="province_change('district_id2',this);" >
<option value="0">โปรดเลือก</option>
	<?php foreach($provinces as $row){?>
	<option value="<?php echo $row["province_id"]; ?>"><?php echo $row["province_name"]; ?></option>
	<?php } ?>
</select>
</div>
 <div class="field" >
<div>เขต/อำเภอ:<?php echo form_error('district_id2', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="district_id2" onchange="district_change('sub_district_id2',this);">
<option>โปรดเลือก</option>
</select>
</div>
 <div class="field" >
<div>ตำบล/แขวง:<?php echo form_error('sub_district_id2', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="sub_district_id2" >
<option>โปรดเลือก</option>

</select>
</div>

 <div class="field" >
<div>รหัสไปรษณีย์:<?php echo form_error('zipcode2', '<span class="field-error">', '</span>'); ?></div><br/>
<input type="text" name="zipcode2"  value="<?php echo set_value("zipcode2",$cust["zipcode2"]); ?>"/>
</div>

<div style="clear: both;"></div>

 <div class="field" >
<div>เบอร์โทร: Ex 089999999<?php echo form_error('mobile', '<span class="field-error">', '</span>'); ?></div><br/>
<input  style="width:200px;" type="text" name="mobile"  value="<?php echo set_value("mobile",$cust["mobile"]); ?>"/>
</div>

 <div class="field" style="width:250px;" >
<div>อีเมล์ Ex xxx@hotmail.com:<?php echo form_error('email', '<span class="field-error">', '</span>'); ?></div><br/>
<input style="width:200px;" type="text" name="email"  value="<?php echo set_value("email",$cust["email"]); ?>"/>
</div>
<div style="clear: both;"></div>
</div>











<div id="form_right">

<div id="form_h3"></div>
	 <div class="field2" >
		<div>สถานะถาพ:<?php echo form_error('status', '<span class="field-error">', '</span>'); ?></div><br/>
		<div class="field_box">
		<input <?php echo set_radio('status', '0' ,$this->udelight->is_chek_radio(0,$cust["status"])); ?>  class="radi" type="radio"" name="status"  value="0"/ >โสด
		 <input <?php echo set_radio('status', '1',$this->udelight->is_chek_radio(1,$cust["status"])); ?>  class="radi" type="radio"" name="status"  value="1"/ >สมรส
	</div>
</div>


<div class="field2" style="width:200px;" >
	<div>จำนวนบุตร:<?php echo form_error('have_child', '<span class="field-error">', '</span>'); ?></div><br/>
	<div class="field_box">
		<input <?php echo set_radio('have_child', '0',$this->udelight->is_chek_radio(0,$cust["have_child"])); ?> class="radi" type="radio" name="have_child"  value="0"/>ไม่มีบุตร 
		<input <?php echo set_radio('have_child', '1',$this->udelight->is_chek_radio(1,$cust["have_child"])); ?> class="radi" type="radio" name="have_child"  value="1"/>
		มีบุตร <input  type="text" style="width:25px;" name="child_total" value ="<?php echo set_value("child_total",$cust["child_total"]); ?>" /> คน
	</div>
</div>

<div style="clear: both;"></div>
 <div class="field2" >
 <div>อาชีพ:<?php echo form_error('careers[]', '<span class="field-error">', '</span>'); ?></div><br/>
	<div class="field_box" style="height: 45px; width:470px;">
		<?php $careers = $this->db->query("select * from careers")->result_array(); ?>
		<?php foreach($careers as $row){ ?>
		<div class="check_list">
		<input class="radi" type="checkbox" <?php echo set_checkbox('careers[]', $row["career_id"],$this->udelight->is_check_box("register_career_relation","career_id",$cust["register_id"],$row["career_id"])); ?>   name="careers[]" value ="<?php echo $row["career_id"] ?>"  /> <?php echo $row["career_name"]; ?>
		</div>
		<?php } ?>
       </div>
</div>

 <div class="field" >
<div>รายได้ต่อเดือน:<?php echo form_error('sbase_id', '<span class="field-error">', '</span>'); ?></div><br/>

<select name="sbase_id" >
<option value="0">โปรดเลือก</option>
<?php $salary_bases = $this->db->query("select * from salary_bases")->result_array(); ?>
<?php foreach($salary_bases as $row){ ?>

<option value="<?php echo $row["sbase_id"]; ?>"><?php echo $row["salary_base"]; ?></option>

<?php } ?>
</select>
</div>

 <div class="field" >
<div>ต้องการผ่อนต่อเดือน:<?php echo form_error('mbase_id', '<span class="field-error">', '</span>'); ?></div><br/>

<select name="mbase_id">
<option value="0">โปรดเลือก</option>
<?php $monthly_bases = $this->db->query("select * from monthly_bases")->result_array(); ?>
<?php foreach($monthly_bases as $row){ ?>

<option value="<?php echo $row["mbase_id"] ?>"><?php echo $row["monthly_base"]; ?></option>

<?php } ?>
</select>
</div>



 <div class="field" >
<div>งบประมาณที่ต้องการซื้อ:<?php echo form_error('budget_id', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="budget_id">
<option value="0">โปรดเลือก</option>
<?php $salary_bases = $this->db->query("select * from budgets")->result_array(); ?>
<?php foreach($salary_bases as $row){ ?>

<option value="<?php echo $row["budget_id"]; ?>" ><?php echo $row["budget"]; ?></option>

<?php } ?>
</select>
</div>

 <div class="field" >
 <div>
ชนิดการซื้อ:<?php echo form_error('buy_type_id', '<span class="field-error">', '</span>'); ?></div><br/>
<select name="buy_type_id">
<option value="0">โปรดเลือก</option>
<?php $buy_types = $this->db->query("select * from buy_types")->result_array(); ?>
<?php foreach($buy_types as $row){ ?>

<option value="<?php echo $row["buy_type_id"] ?>"><?php echo $row["buy_type_name"]; ?></option>

<?php } ?>
</select>
</div>
<div style="clear: both;"></div>
 <div class="field2" >
 <div>จุดประสงค์ของการซื้อ:<?php echo form_error('purposies[]', '<span class="field-error">', '</span>'); ?></div><br/>
<div class="field_box" style="height: 45px; width:470px;">
<?php $purposies = $this->db->query("select * from purposies where purpose_id not in (5)")->result_array(); ?>
<?php foreach($purposies as $row){ ?>
<div class="check_list">
<input class="radi" type="checkbox" <?php echo set_checkbox('purposies[]', $row["purpose_id"],$this->udelight->is_check_box("register_purpose_relation","purpose_id",$cust["register_id"],$row["purpose_id"])); ?>   name="purposies[]" value ="<?php echo $row["purpose_id"] ?>"  /> <?php echo $row["purpose_name"]; ?>
</div>
<?php } ?>
<div class="check_list" style="width:200px;">

<input type="checkbox"  <?php echo set_checkbox('purposies[]', 5); ?>  value="5" name="purposies[]" class="radi"> เพื่อเอาไว้ลงทุนมากกว่า 10 ห้อง</div>
</div>
</div>

 <div class="field2" >
 <div>
ประเภทสินค้าที่สนใจ:<?php echo form_error('product_types[]', '<span class="field-error">', '</span>'); ?></div><br/>
<div class="field_box" style="height: 45px; width:470px;">
<?php $product_types = $this->db->query("select * from product_types")->result_array(); ?>
<?php foreach($product_types as $row){ ?>
<div class="check_list">
<input class="radi" type="checkbox"  <?php echo set_checkbox('product_types[]', $row["product_type_id"],$this->udelight->is_check_box("register_product_type_relation","product_type_id",$cust["register_id"],$row["product_type_id"])); ?>  name="product_types[]" value ="<?php echo $row["product_type_id"] ?>"  /> <?php echo $row["product_type_name"]; ?>
</div>
<?php } ?>
</div>
</div>




</div>
<div style="clear: both;"></div>
<div></div>
<div style="clear: both;"></div>
<div id="form_footer" >

<img src="include/images/save.png" class="summit" onclick="javascript:document.forms['myform'].submit();" >

</div>

</form>
<div style="clear: both;"></div>

<?php //print_r($cust); ?>
<?php //print_r($_POST); ?>
<script>

$(document).ready(function() {

	set_select("birth_day",'<?php echo set_value("birth_day",$cust["birth_day"]); ?>');
	set_select("birth_month",'<?php echo set_value("birth_month",$cust["birth_month"]); ?>');
	set_select("birth_year",'<?php echo set_value("birth_year",($cust["birth_year"]+543)); ?>');

	set_select("sbase_id",'<?php echo set_value("sbase_id",$cust["sbase_id"]); ?>');
	set_select("mbase_id",'<?php echo set_value("mbase_id",$cust["mbase_id"]); ?>');
	set_select("budget_id",'<?php echo set_value("budget_id",$cust["budget_id"]); ?>');
	set_select("buy_type_id",'<?php echo set_value("buy_type_id",$cust["buy_type_id"]); ?>');
	

	set_select("prefix_name",'<?php echo set_value("prefix_name",$cust["prefix_name"]); ?>');
	set_select("province_id",'<?php echo set_value("province_id",$cust["province_id"]); ?>');
	init_district('district_id','<?php echo set_value("province_id",$cust["province_id"]); ?>','<?php echo set_value("district_id",$cust["district_id"]); ?>');
	init_sub_district('sub_district_id','<?php echo set_value("district_id",$cust["district_id"]); ?>','<?php echo set_value("sub_district_id",$cust["sub_district_id"]); ?>');

	set_select("province_id2",'<?php echo set_value("province_id2",$cust["province_id2"]); ?>');
	init_district('district_id2','<?php echo set_value("province_id2",$cust["province_id2"]); ?>','<?php echo set_value("district_id2",$cust["district_id2"]); ?>');
	init_sub_district('sub_district_id2','<?php echo set_value("district_id2",$cust["district_id2"]); ?>','<?php echo set_value("sub_district_id2",$cust["sub_district_id2"]); ?>');
});
function copy_to_contact()
{
	var province_id = $("select[name=province_id]").val();
	var district_id =  $("select[name=district_id]").val();
	var sub_district_id = $("select[name=sub_district_id]").val();
	
	set_select("province_id2",province_id);
	init_district('district_id2',province_id,district_id);
	init_sub_district('sub_district_id2',district_id,sub_district_id);

	$("input[name=home_street2]").val($("input[name=home_street]").val());
	$("input[name=moo2]").val($("input[name=home_street]").val());
	$("input[name=soi2]").val($("input[name=soi]").val());
	$("input[name=road2]").val($("input[name=road]").val());
	$("input[name=zipcode2]").val($("input[name=zipcode]").val());
	
	
}

function set_select(key,value)
{
	$("select[name="+key+"] option[value="+value+"]").attr('selected', 'selected');
	
 }
function init_district(field,parent,current)
{
	$.ajax({
		  url: "<?php echo site_url("service/get_district/"); ?>/"+parent+"/"+current,
		  cache: true,
		  success: function(html){
		    $(".form select[name="+field+"]").html(html);
			
		  }
		});
}
function init_sub_district(field,parent,current)
{
	var url ="<?php echo site_url("service/get_sub_district/"); ?>/"+parent+"/"+current;
	//alert(url);
	$.ajax({
		  url: url,
		  cache: true,
		  success: function(html){
		    $(".form select[name="+field+"]").html(html);
		   // alert(html);
			
		  }
		});
}
function province_change(field,obj)
{
	
	$.ajax({
	  url: "<?php echo site_url("service/get_district/"); ?>/"+obj.value,
	  cache: true,
	  success: function(html){
	    $(".form select[name="+field+"]").html(html);
	    
	  }
	});
}

function district_change(field,obj)
{
	
	$.ajax({
	  url: "<?php echo site_url("service/get_sub_district/"); ?>/"+obj.value,
	  cache: true,
	  success: function(html){
	    $(".form select[name="+field+"]").html(html);
		
	  }
	});
}
</script>